package domain

import (
	"errors"
	"regexp"
)

var (
	areaRegexp  = regexp.MustCompile("(市)((.+)(区|县))")
	errNotMatch = errors.New("未识别的地址")
	cityRegexp  = regexp.MustCompile("(省|自治区|行政区)((.+)市)")
)

func GetAreaName(addr string) (string, error) {
	var matches [][]string = areaRegexp.FindAllStringSubmatch(addr, -1)
	if len(matches) == 0 {
		return "", errNotMatch
	}
	return matches[0][2], nil
}

func GetCityName(addr string) (string, error) {
	var matches [][]string = cityRegexp.FindAllStringSubmatch(addr, -1)
	if len(matches) == 0 {
		return "", errNotMatch
	}
	return matches[0][2], nil
}
